// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    nbFrontColor: '#000000',
    nbBackgroundColor: '#ffffff',

    navList: [{
        name: '头条',
        type: "top"
      },
      {
        name: '社会',
        type: "top"
      }, {
        name: '国内',
        type: "guonei"
      }, {
        name: '国际',
        type: "guoji"
      }, {
        name: '娱乐',
        type: "yule"
      }, {
        name: '体育',
        type: "tiyu"
      },
    ],
    current: 0,
    page: 1,
    page_size: 10,
    list: []
  },
  onLoad() {
    this.getData()
  },
  getData() {
    let data = {
      type: this.data.navList[0].type,
      key: app.globalData.key,
      page: this.data.page,
      page_size: this.data.page_size
    }
    wx.request({
      url: 'http://v.juhe.cn/toutiao/index',
      data: data,
      success: res => {
        let temp = [];
        temp = res.data.result.data;
        if (this.data.page === 1) {
          this.setData({
            list: temp
          })
        } else {
          this.setData({
            list: this.data.list.concat(temp)
          })
        }

      }
    })
  },
  tapItem(e) {
    let index = e.currentTarget.dataset.index;
    let type = e.currentTarget.dataset.type;
    this.data.page=1;
    this.data.list=[];
    this.setData({
      current: index,
      type: type
    })
    this.getData()

  },
  loadMore() {
    console.log(222)
    this.data.page++;
    this.getData()
  }


})